from MySensor import FrontBackCheckRun1,BackSensorCheck
from MyMotor import bluetooth,Tracking,TestHowRun,HowRun,HardStop,RaspiTracking
from pyb import delay
from tls01 import TLS01
from pyb import UART
import time

# 构建蓝牙模块对象（串口）
BLE = TLS01(1, 9600)  # 设置串口号3和波特率, TX--B6, RX--B7


mode = 1  # 1: 表示蓝牙模式 2: 循迹模式/
def RunMain():
    global mode
    while 1:
        if mode==3:#停机
            break
        if mode==1:#蓝牙
            mode=bluetooth(BLE)
        elif mode==2:#循迹
            mode=Tracking(BLE)
        elif mode=="4":#树莓派控制
            mode==RaspiTracking(BLE)
        else:
            pass


def TestTurn():#测转的时间
    global mode
    while 1:
        if mode==3:#停机
            break
        if mode==1:#蓝牙
            mode=bluetooth(BLE)
        elif mode==2:#循迹
            #mode=Tracking(BLE)
            lrg=FrontBackCheckRun1()[0]
            TestHowRun(lrg)
            t1=time.ticks_ms()
            while 1:
                print(lrg)
                if FrontBackCheckRun1()[0]=='g':
                    TestHowRun('c')
                    break
            delta = time.ticks_diff(time.ticks_ms(), t1)
            print(delta)
            mode=1
        else:
            pass
def TestDelay():#测延时时间转的角度
    global mode
    while 1:
        if mode==3:#停机
            break
        if mode==1:#蓝牙
            mode=bluetooth(BLE)
        elif mode==2:#循迹
            TestHowRun('m')
            delay(100)
            TestHowRun('c')
            mode=1
        else:
            pass
def TestSensor():
    global mode
    while 1:
        if mode==3:#停机
            break
        if mode==1:#蓝牙
            mode=bluetooth(BLE)
        elif mode==2:#循迹
            print(BackSensorCheck())
            mode=1
        else:
            pass
HardStop()
RunMain()
#TestTurn()
#TestSensor()
#TestDelay()
print('End')

